package com.hyg.lib_music.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hyg.lib_common.DataModel.Music.MusicCateData;
import com.hyg.lib_music.R;

import me.drakeet.multitype.ItemViewBinder;

public class MusicCateFooterViewBinder extends ItemViewBinder<MusicCateData, MusicCateFooterViewBinder.ViewHolder> {

    private OnMusicCateFooterClickListener onMusicCateClickListener;

    @Override
    protected @NonNull
    ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_music_cate_footer, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull MusicCateData musicCateData) {
        holder.setData(musicCateData);
    }

    class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public MusicCateData musicCateData;
        private @NonNull
        LinearLayout music_cate;
        private @NonNull
        TextView cateName;

        ViewHolder(@NonNull View itemView) {
            super(itemView);
            music_cate = itemView.findViewById(R.id.music_cate);
            cateName = itemView.findViewById(R.id.cateName);
            music_cate.setOnClickListener(this);
        }

        void setData(@NonNull final MusicCateData musicCateData) {
            this.musicCateData = musicCateData;
            cateName.setText(musicCateData.categoryName);
        }

        @Override
        public void onClick(View view) {
            if (onMusicCateClickListener != null) {
                if (view.getId() == R.id.music_cate) {
                    onMusicCateClickListener.onItemClick(view, this.musicCateData);
                }
            }
        }
    }

    // 自定义点击事件
    public void setOnMusicCateFooterClickListener(OnMusicCateFooterClickListener onMusicCateFooterClickListener) {
        this.onMusicCateClickListener = onMusicCateFooterClickListener;
    }

    public interface OnMusicCateFooterClickListener {
        void onItemClick(View view, MusicCateData musicCateData);
    }
}